package com.yunxi.finance.pojo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
import java.io.Serializable;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 金融产品维护
 * </p>
 *
 * @author XUQI
 * @since 2019-12-02
 */
@Data
@EqualsAndHashCode(callSuper = false)

@ApiModel(value = "FinanceProduct对象", description = "金融产品维护")
public class FinanceProductVO implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "ID")
    private String id;

    @ApiModelProperty(value = "方案类型：1推荐方案 2自选方案")
    private Integer planType;

    @ApiModelProperty(value = "产品类别：1银行类产品 2 融资租聘类产品")
    private Integer productType;

    @ApiModelProperty(value = "产品名称")
    private String productName;

    @ApiModelProperty(value = "金融机构")
    private String financeInstitution;

    @ApiModelProperty(value = "金融机构")
    private String financeInstitutionName;

    @ApiModelProperty(value = "计算方式 1:利率 2:费率")
    private Integer calculation;

    @ApiModelProperty(value = "利率值/费率值")
    private BigDecimal ratio;

    @ApiModelProperty(value = "一次性手续费A")
    private BigDecimal oneTimePriceA;

    @ApiModelProperty(value = "一次性手续费B")
    private BigDecimal oneTimePriceB;

    @ApiModelProperty(value = "首付比例最大值")
    private BigDecimal downPaymentMax;

    @ApiModelProperty(value = "首付比例最小值")
    private BigDecimal downPaymentMin;

    @ApiModelProperty(value = "首付比例刻度")
    private BigDecimal downPaymentScale;

    @ApiModelProperty(value = "首付比例")
    private BigDecimal downPaymentRatio;

    @ApiModelProperty(value = "首付比例集合（根据最大最小刻度生成）")
    private List<Integer> downPaymentList = new ArrayList<>();

    @ApiModelProperty(value = "保证金比例最大值")
    private BigDecimal bailMax;

    @ApiModelProperty(value = "保证金比例最小值")
    private BigDecimal bailMin;

    @ApiModelProperty(value = "保证金刻度")
    private BigDecimal bailScale;

    @ApiModelProperty(value = "保证金比例集合（根据最大最小刻度生成）")
    private List<Integer> bailList = new ArrayList<>();

    @ApiModelProperty(value = "保证金比例")
    private BigDecimal bailRatio;

    @ApiModelProperty(value = "期限")
    private String deadline;

    @ApiModelProperty(value = "期限")
    private List<Integer> deadlineList = new ArrayList<>();

    @ApiModelProperty(value = "尾款比例最大值")
    private BigDecimal balanceRatioMax;

    @ApiModelProperty(value = "尾款比例最小值")
    private BigDecimal balanceRatioMin;

    @ApiModelProperty(value = "尾款比例刻度")
    private BigDecimal balanceRatioScale;

    @ApiModelProperty(value = "尾款比例集合（根据最大最小刻度生成）")
    private List<Integer> balanceRatioList = new ArrayList<>();

    @ApiModelProperty(value = "尾款比例")
    private BigDecimal balanceRatio;

    @ApiModelProperty(value = "尾款金额")
    private BigDecimal balanceAmount;

    @ApiModelProperty(value = "1:显示尾款比例 2:显示尾款金额")
    private Integer balanceShow;

    @ApiModelProperty(value = "校验值")
    private BigDecimal checkValue;

    @ApiModelProperty(value = "适用城市")
    private String city;

    @ApiModelProperty(value = "贴息比例")
    private BigDecimal discountRatio;

    @ApiModelProperty(value = "贴息金额")
    private BigDecimal discountAmount;

    @ApiModelProperty(value = "1:显示贴息比例 2:显示贴息金额")
    private Integer discountShow;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "创建人")
    private String createBy;

    @ApiModelProperty(value = "更新时间")
    private Date updateTime;

    @ApiModelProperty(value = "更新人")
    private String updateBy;

    @ApiModelProperty(value = "版本号")
    private Integer version;


    public void setDownPaymentList() {
        if (this.downPaymentMin == null || this.downPaymentMax == null) {
            return;
        }
        Integer start = downPaymentMin.multiply(new BigDecimal(100)).intValue();
        Integer end = downPaymentMax.multiply(new BigDecimal(100)).intValue();
        Integer scale = this.downPaymentScale.multiply(new BigDecimal(100)).intValue();
        do {
            this.downPaymentList.add(start);
            start = start + scale;
        } while (start < end);
        this.downPaymentList.add(end);
    }


    public void setBailList() {
        if (this.bailMin == null || this.bailMax == null) {
            return;
        }
        Integer start = bailMin.multiply(new BigDecimal(100)).intValue();
        Integer end = bailMax.multiply(new BigDecimal(100)).intValue();
        Integer scale = this.bailScale.multiply(new BigDecimal(100)).intValue();
        do {
            this.bailList.add(start);
            start = start + scale;
        } while (start < end);
        this.bailList.add(end);
    }


    public void setBalanceRatioList() {
        if (this.balanceRatioMin == null || this.balanceRatioMax == null) {
            return;
        }
        Integer start = balanceRatioMin.multiply(new BigDecimal(100)).intValue();
        Integer end = balanceRatioMax.multiply(new BigDecimal(100)).intValue();
        Integer scale = this.balanceRatioScale.multiply(new BigDecimal(100)).intValue();
        do {
            this.balanceRatioList.add(start);
            start = start + scale;
        } while (start < end);
        this.balanceRatioList.add(end);
    }

    public void setDeadlineList() {
        if (StringUtils.isEmpty(this.deadline)) {
            return;
        }
        List<String> list = Arrays.asList(deadline.split(";"));
        list.forEach(s -> {
            this.deadlineList.add(Integer.valueOf(s));
        });
    }
}
